#include "netmain.h"
#include "mytcpserver.h"
NetMain * NetMain::obj = nullptr;
NetMain::NetMain(QObject *parent)
    : QObject{parent}
    , server(new MyTcpServer)
{

}

NetMain *NetMain::getObject()
{
    if(obj == nullptr)
        obj = new NetMain;
    return obj;
}

void NetMain::netInit()
{

}

bool NetMain::netStart()
{
    netStop();
    bool ok = server->listen(QHostAddress::Any, 10010);
    if(!ok)
    {
        errorInfo = "Net device service start error!";
        return false;
    }
    return ok;
}

void NetMain::netStop()
{
    server->serverCloseAndClear();
}

QString NetMain::netGetLastErrorInfo()
{
    return errorInfo;
}
